<!--
 * @Description: 我的订单页面
 * @Author: LiKun
 * @Date: 2021-12-14 20:42:55
 * @LastEditors: LiKun
 * @LastEditTime: 2022-01-05 15:55:04
-->
<template>
  <div class="order">
    <van-nav-bar title="我的工单" />
    <van-tabs @click="tabClickHandler" v-model="active">
      <van-tab title="进行中"> </van-tab>
      <van-tab title="已完成"> </van-tab>
    </van-tabs>
    <div class="orderList">
      <div
        class="box"
        v-for="(item, index) in orderList"
        :key="index"
        @click="$router.push({ path: '/orderDetails', query: item })"
      >
        <div class="left">
          <img width="70px" src="../../assets/order.png" alt="" />
        </div>
        <div class="right">
          <div>
            <strong>工单状态：</strong>
            <van-tag
              size="medium"
              v-if="item.status == '已完成'"
              type="success"
              >{{ item.status }}</van-tag
            >
            <van-tag size="medium" v-else type="primary">{{
              item.status
            }}</van-tag>
          </div>
          <div><strong>工单类型：</strong>{{ item.type }}</div>
          <div><strong>申报时间：</strong>{{ item.create_time | datefmt }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/utils/request.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      active: 0,
      orderList: [],
      params: {
        page: 1,
        pageSize: 100,
      },
    };
  },
  computed: {
    ...mapState("user", ["info"]),
  },
  methods: {
    // 查询本人工单
    getAllWorkerOrdersByStatus() {
      switch (this.active) {
        case 0:
          this.params.status = "进行中";
          this.params.account_id = this.info.id;
          break;
        case 1:
          this.params.status = "已完成";
          this.params.account_id = this.info.id;
          break;
      }
      get("/workorder/pageQuery", this.params).then((res) => {
        this.orderList = res.data.list;
      });
    },
    // 标签点击事件
    tabClickHandler(name, title) {
      this.params.status = title;
      // 重载数据
      this.getAllWorkerOrdersByStatus();
    },
  },
  created() {
    this.getAllWorkerOrdersByStatus();
  },
};
</script>
<style scoped>
.box {
  height: 95px;
  margin: 10px 20px;
  padding: 10px;
  border: 1px solid rgb(156, 154, 154);
  border-radius: 10px;
  display: flex;
  cursor: pointer;
}
.left {
  width: 85px;
}
.right {
  width: calc(100% - 85px);
}
.right > div {
  height: 24px;
  line-height: 24px;
  font-size: 16px;
}
</style>
